#include "qtablewidgetex.h"

QTableWidgetEx::QTableWidgetEx()
{

}

QTableWidgetEx::QTableWidgetEx(QWidget *parent)
    :QTableWidget(parent)//子类必须显式调用父类有参构造，否则父类的有参构造无法被调用
{

    Act_DelRow = new QAction(tr("删除选中行"), this);
    Act_ClearAll = new QAction(tr("清空"), this);

    menu=new QMenu(this);

    menu->addAction(Act_ClearAll); //Act_ClearAll
    menu->addAction(Act_DelRow); //添加菜单项Act_DelRow


    QObject::connect(this->Act_DelRow,SIGNAL(triggered()),
                     this,SLOT(on_Act_DelRow_triggered()));//右键菜单的动作
    QObject::connect(this->Act_ClearAll,SIGNAL(triggered()),
                     this,SLOT(on_Act_ClearAll_triggered()));//右键菜单的动作

}
void QTableWidgetEx::contextMenuEvent(QContextMenuEvent *e)
{
    menu->exec( e->globalPos() );//在光标位置处弹出菜单
}
void QTableWidgetEx::on_Act_DelRow_triggered()
{

    this->removeRow(this->currentRow());//删除选中的行

}
void QTableWidgetEx::on_Act_ClearAll_triggered()
{
    this->setRowCount(0);//全删
}
